/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 04.03.2012 by jkonopka
 */
package de.sql.toolkit.reader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.sql.toolkit.model.Table;
import de.sql.toolkit.provider.SelectProvider;
import de.sql.toolkit.provider.TableProvider;

/**
 * @author jkonopka
 * 
 */
public class InsertScriptReader extends AbstractReader<Map<String, List<Map<String, Object>>>> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3092995104790782257L;
	private String schema;

	/**
	 * @param schema
	 */
	public InsertScriptReader(String schema) {
		super();
		this.schema = schema;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.reader.IReader#read()
	 */
	@Override
	public Map<String, List<Map<String, Object>>> read() throws Exception {
		final Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
		final TableProvider tblProvider = new TableProvider();
		final List<Table> tables = tblProvider.select(getSchema());
		for (final Table table : tables) {
			final SelectProvider provider = new SelectProvider();
			final String tablename = table.getName();
			final List<Map<String, Object>> values = provider.select(getSchema(), tablename);
			result.put(tablename, values);
		}

		return result;
	}

	/**
	 * @return the schema
	 */
	public String getSchema() {
		return schema;
	}

	/**
	 * @param schema the schema to set
	 */
	public void setSchema(String schema) {
		this.schema = schema;
	}

}
